﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ShowPanel:MonoBehaviour
{
    public GameObject _ScrollRect;
    public GameObject _LogPeopleGround;
    private RectTransform _LogPeopleRT;
    private GameObject _LogPeoplePrefabs;
    private GameObject _CurrentLogPeoplePrefabs;


    public  Text text;
    private static ShowPanel m_Instance;
    public static ShowPanel Insatnce
    {
        get { return m_Instance; }
    }

    private void Awake()
    {
        m_Instance = this;
    }

    private void Start()
    {
     
        _ScrollRect.GetComponent<ScrollRect>().onValueChanged.AddListener(OnShowValeu);
        _LogPeopleRT = _LogPeopleGround.GetComponent<RectTransform>();
        _LogPeoplePrefabs = Resources.Load<GameObject>("View/ShowPanel/Item/LogPeopleItem");
    }


    private void Update()
    {
     
            
           



    }

    /// <summary>
    /// 让显示框底边一直在下面
    /// </summary>
    /// <param name="arg0"></param>
    private void OnShowValeu(Vector2 arg0)
    {
        if (_LogPeopleRT == null) return;
        if (_LogPeopleRT.sizeDelta.y - _LogPeopleRT.sizeDelta.x <= 0)
        {
            _LogPeopleRT.anchoredPosition =new Vector2 (_LogPeopleRT.anchoredPosition.x,0);
        }
        else
        {
            float temp = _LogPeopleRT.sizeDelta.y - _LogPeopleRT.sizeDelta.x;
            _LogPeopleRT.anchoredPosition = new Vector2(_LogPeopleRT.anchoredPosition.x, temp);
        }
    }
 
    /// <summary>
    /// 创建一个客户端连接
    /// </summary>
    public static void CreatClientConnent(string id)
    {
        //_CurrentLogPeoplePrefabs = GameObject.Instantiate(_LogPeoplePrefabs, _LogPeopleGround.transform);
        //_CurrentLogPeoplePrefabs.GetComponent<LogPeopleItem>()._NamneText.text = _LogPeopleList[_LastIndex];
        // _CurrentLogPeoplePrefabs.GetComponent<LogPeopleItem>()._NamneText.text = id;
        // StartCoroutine(IECreatClientConnent(id));

        test( id);

    }
    public void test(string id)
    {
        text.text = "connet:" + id + "\n";
    }
    //private IEnumerator IECreatClientConnent(string id)
    //{
    //    yield return null;
    //    _CurrentLogPeoplePrefabs = GameObject.Instantiate(_LogPeoplePrefabs, _LogPeopleGround.transform);
    //    _CurrentLogPeoplePrefabs.GetComponent<LogPeopleItem>()._NamneText.text = id;
    //}


    //#region override
    //public override void Start()
    //{
    //    base.Start();

    //}

    //public override void OnDestroy()
    //{
    //    base.OnDestroy();
    //}
    //public override void Open()
    //{
    //    base.Open();

    //}
    //public override void Close()
    //{
    //    base.Close();
    //}
    //void Init()
    //{
    //}

    //public override void SetInfo(ArrayList list)
    //{

    //}
    //#endregion



}
